import "./public-path";
import { createRoot } from "react-dom/client";
import { BrowserRouter } from "react-router-dom";

import { store } from "./app/store";
import { Provider } from "react-redux";

import App from "./App";

import "./locales/i18n"; // 国际化

import "antd/dist/antd.less";
import "./styles/index.css";

let root: any;

function render(props: any) {
  const container = props.container
    ? props.container.querySelector("#root")
    : document.querySelector("#root");
  root = createRoot(container as HTMLElement);
  root.render(
    // <React.StrictMode>
    <BrowserRouter basename={window.__POWERED_BY_QIANKUN__ ? "/hospital" : "/"}>
      <Provider store={store}>
        <App />
      </Provider>
    </BrowserRouter>
    // </React.StrictMode>
  );
}

if (!window.__POWERED_BY_QIANKUN__) {
  render({});
}

export async function bootstrap() {}

export async function mount(props: any) {
  const state = props.actions.getGlobalState();
  console.log(state);

  render(props);
}

export async function unmount(props: any) {
  root.unmount();
}
